/**
 * 
 */
package br.edu.ufcg.embedded.mysocial;

/**
 * @author daniel
 *
 */
import java.awt.Dimension;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.jgraph.JGraph;
import org.jgraph.graph.GraphModel;
import org.jgrapht.Graph;
import org.jgrapht.ext.JGraphModelAdapter;
import org.jgrapht.graph.DefaultEdge;

import com.jgraph.layout.JGraphFacade;
import com.jgraph.layout.JGraphModelFacade;
import com.jgraph.layout.organic.JGraphFastOrganicLayout;
import com.jgraph.layout.tree.JGraphTreeLayout;

import br.embedded.socialapp.business.Usuario;

public class JGraphSwing extends JFrame {

	public static void main(String[] args) {
		
		drawGraph(ClientWS.createGraph(9, 3));
	}
	
	public static void drawGraph(Graph<Usuario, DefaultEdge> graph)
	{
		GraphModel model = new JGraphModelAdapter(graph);
				
	    JGraphFacade  facade = new JGraphModelFacade(model); // Pass the facade the JGraph instance
	    //JGraphTreeLayout layout = new JGraphTreeLayout(); // Create an instance of the appropriate layout
	    JGraphFastOrganicLayout l = new  JGraphFastOrganicLayout();
	    
	    l.setInitialTemp(20.0);
	    l.setForceConstant(250.0);
	    
	    /*layout.setOrientation(SwingConstants.NORTH);
	    layout.setAlignment(SwingConstants.TOP);
	    
	    layout.setLevelDistance(400.0);
	    layout.setNodeDistance(150);
	    layout.setCombineLevelNodes(true);
	    layout.setRouteTreeEdges(false);
	    layout.setPositionMultipleTrees(true);
	    layout.setTreeDistance(50);*/
	    
	    l.run(facade); // Run the layout on the facade.
	    Map nested = facade.createNestedMap(true, true); // Obtain a map of the resulting attribute changes from the facade
	    model.edit(nested, null, null, null);

		// Show in Frame
		JFrame frame = new JFrame("Friendship Graph");
		frame.setPreferredSize(new Dimension(1024, 768));
		frame.getContentPane().add(new JScrollPane(new JGraph(model)));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}	
}